/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package vista.personas.pacientes;

import java.util.List;
import javax.swing.JComboBox;
import javax.swing.JTextField;
import util.GestorComponenteVista;
import util.components.ITablaABMPnl;
import util.components.IntegerTextField;
import util.components.LongTextField;
import util.validation.annotation.Filter;

/**
 *
 * @author raul
 */
public class PacientesPnl extends javax.swing.JPanel implements ITablaABMPnl {

    private String nombrePanel="Pacientes";
    private GestorVistaPacientesPnl gestorVista;
    
    /** Creates new form pacientesPnl */
    public PacientesPnl() {
        initComponents();
    }

    public PacientesPnl(GestorVistaPacientesPnl gestorVista) {
        this();
        this.gestorVista = gestorVista;
        pacienteABMPnl.setGestorVista(gestorVista);
    }
    
    public GestorVistaPacientesPnl getGestorVista() {
        return gestorVista;
    }

    public void setGestorVista(GestorVistaPacientesPnl gestorVista) {
        this.gestorVista = gestorVista;
    }

    @Filter
    public JTextField getNombreTxt() {
        return nombreTxt;
    }

    @Filter
    public JTextField getApellidoTxt() {
        return apellidoTxt;
    }

    @Filter
    public IntegerTextField getNroDocumentoTxt() {
        return nroDocumentoTxt;
    }

    @Filter

    public LongTextField getNroHistoriaClinicaTxt() {
        return nroHistoriaClinicaTxt;
    }

    public IntegerTextField getCodigoPostalTxt() {
        return codigoPostalTxt;
    }

    @Filter
    public JComboBox getProvinciaCmb() {
        return provinciaCmb;
    }

    @Filter
    public JComboBox getLocalidadCmb() {
        return localidadCmb;
    }
    
    @Override
    public void agregarFilaTabla(Object[] fila) {
        GestorComponenteVista.agregarFilaTabla(pacienteABMPnl.getTabla(),fila);
    }

    @Override
    public void cargarTitulosTabla(Object[] titulos){
        int [] anchos   ={0, 20, 100,20,20,100,20};
        GestorComponenteVista.cargarTitulosTabla(pacienteABMPnl.getTabla(),titulos,anchos);
    }

    @Override
    public void actualizarTabla() {
        pacienteABMPnl.actualizarTabla();
    }

    public void cargarComboProvincia(List provincias) {
        GestorComponenteVista.cargarCombo(provinciaCmb, provincias);
    }

    public void cargarComboLocalidad(List localidades){
        GestorComponenteVista.cargarCombo(localidadCmb, localidades);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final PacientesPnl other = (PacientesPnl) obj;
        if ((this.nombrePanel == null) ? (other.nombrePanel != null) : !this.nombrePanel.equals(other.nombrePanel)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 37 * hash + (this.nombrePanel != null ? this.nombrePanel.hashCode() : 0);
        return hash;
    }
    
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pacienteABMPnl = new util.components.TablaABMPnl();
        generarListadoPacietesBtn = new javax.swing.JButton();
        busquedaPnl = new util.components.RoundedTitlePanel();
        buscarBtn = new javax.swing.JButton();
        nombreTxt = new util.components.CamelCaseTextField();
        jLabel1 = new javax.swing.JLabel();
        apellidoTxt = new util.components.CamelCaseTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        nroDocumentoTxt = new util.components.IntegerTextField();
        buscarLocalidadBtn = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        codigoPostalTxt = new util.components.IntegerTextField();
        jLabel6 = new javax.swing.JLabel();
        localidadCmb = new javax.swing.JComboBox();
        provinciaCmb = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        nroHistoriaClinicaTxt = new util.components.LongTextField();
        historiaClinicaBtn = new javax.swing.JButton();

        generarListadoPacietesBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/prescription_64.png"))); // NOI18N
        generarListadoPacietesBtn.setText("Generar listado");
        generarListadoPacietesBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                generarListadoPacietesBtnActionPerformed(evt);
            }
        });

        busquedaPnl.setTitle("Búsqueda");

        buscarBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/zoom.png"))); // NOI18N
        buscarBtn.setText("Buscar");
        buscarBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buscarBtnActionPerformed(evt);
            }
        });

        nombreTxt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buscarBtnActionPerformed(evt);
            }
        });

        jLabel1.setText("Nombre");

        apellidoTxt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buscarBtnActionPerformed(evt);
            }
        });

        jLabel2.setText("Apellido");

        jLabel5.setText("Nro Documento");

        nroDocumentoTxt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buscarBtnActionPerformed(evt);
            }
        });
        nroDocumentoTxt.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                nroDocumentoTxtKeyTyped(evt);
            }
        });

        buscarLocalidadBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/zoom.png"))); // NOI18N
        buscarLocalidadBtn.setToolTipText("Buscar localidad");
        buscarLocalidadBtn.setBorderPainted(false);
        buscarLocalidadBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buscarLocalidadBtnActionPerformed(evt);
            }
        });

        jLabel7.setText("C.P.");

        codigoPostalTxt.setAgruparMiles(false);
        codigoPostalTxt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                codigoPostalTxtbuscarLocalidadBtnActionPerformed(evt);
            }
        });
        codigoPostalTxt.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                codigoPostalTxtKeyTyped(evt);
            }
        });

        jLabel6.setText("Localidad");

        provinciaCmb.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                provinciaCmbActionPerformed(evt);
            }
        });

        jLabel8.setText("Provincia");

        jLabel3.setText("Nro Historia Clínica");

        nroHistoriaClinicaTxt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buscarBtnActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout busquedaPnlLayout = new javax.swing.GroupLayout(busquedaPnl);
        busquedaPnl.setLayout(busquedaPnlLayout);
        busquedaPnlLayout.setHorizontalGroup(
            busquedaPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(busquedaPnlLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(busquedaPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(busquedaPnlLayout.createSequentialGroup()
                        .addGroup(busquedaPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel7))
                        .addGap(28, 28, 28)
                        .addGroup(busquedaPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(busquedaPnlLayout.createSequentialGroup()
                                .addComponent(nombreTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel2)
                                .addGap(29, 29, 29)
                                .addComponent(apellidoTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(busquedaPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(buscarBtn)
                                .addGroup(busquedaPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(localidadCmb, javax.swing.GroupLayout.PREFERRED_SIZE, 392, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(busquedaPnlLayout.createSequentialGroup()
                                        .addComponent(codigoPostalTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(buscarLocalidadBtn)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel8)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(provinciaCmb, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(busquedaPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(busquedaPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(nroHistoriaClinicaTxt, javax.swing.GroupLayout.DEFAULT_SIZE, 142, Short.MAX_VALUE)
                            .addComponent(nroDocumentoTxt, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addComponent(jLabel6))
                .addContainerGap(15, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        busquedaPnlLayout.setVerticalGroup(
            busquedaPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, busquedaPnlLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(busquedaPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nroDocumentoTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(nombreTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addComponent(apellidoTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(busquedaPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(busquedaPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(busquedaPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(codigoPostalTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8)
                            .addComponent(provinciaCmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(buscarLocalidadBtn))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, busquedaPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel3)
                        .addComponent(nroHistoriaClinicaTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(busquedaPnlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(localidadCmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(buscarBtn))
        );

        historiaClinicaBtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/medical_history_64.png"))); // NOI18N
        historiaClinicaBtn.setText("Historia Clinica");
        historiaClinicaBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                historiaClinicaBtnActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pacienteABMPnl, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(generarListadoPacietesBtn)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(historiaClinicaBtn))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(busquedaPnl, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(0, 0, Short.MAX_VALUE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(busquedaPnl, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pacienteABMPnl, javax.swing.GroupLayout.DEFAULT_SIZE, 241, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(generarListadoPacietesBtn)
                    .addComponent(historiaClinicaBtn))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void generarListadoPacietesBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_generarListadoPacietesBtnActionPerformed
        gestorVista.listarTodos();
    }//GEN-LAST:event_generarListadoPacietesBtnActionPerformed

    private void buscarBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buscarBtnActionPerformed
        gestorVista.buscar();
    }//GEN-LAST:event_buscarBtnActionPerformed

    private void buscarLocalidadBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buscarLocalidadBtnActionPerformed
        if (codigoPostalTxt.getValue() != null) {
            gestorVista.buscarLocalidad(codigoPostalTxt.getValue());
        }
    }//GEN-LAST:event_buscarLocalidadBtnActionPerformed

    private void codigoPostalTxtbuscarLocalidadBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_codigoPostalTxtbuscarLocalidadBtnActionPerformed
        if (codigoPostalTxt.getValue() != null) {
            gestorVista.buscarLocalidad(codigoPostalTxt.getValue());
        }
    }//GEN-LAST:event_codigoPostalTxtbuscarLocalidadBtnActionPerformed

    private void codigoPostalTxtKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_codigoPostalTxtKeyTyped
        if (codigoPostalTxt.getText().length() == 5) {
            evt.consume();
        }
    }//GEN-LAST:event_codigoPostalTxtKeyTyped

    private void provinciaCmbActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_provinciaCmbActionPerformed
        if (provinciaCmb.getSelectedItem() != null) {
            getGestorVista().cargarLocalidades(provinciaCmb.getSelectedItem());
        }
    }//GEN-LAST:event_provinciaCmbActionPerformed

    private void nroDocumentoTxtKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_nroDocumentoTxtKeyTyped
        if (nroDocumentoTxt.getText().length() == 8) evt.consume();
    }//GEN-LAST:event_nroDocumentoTxtKeyTyped

    private void historiaClinicaBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_historiaClinicaBtnActionPerformed
        if (pacienteABMPnl.getTabla().getSelectedRow()!=-1) {
            GestorVistaHistoriaClinicaDlg g = new GestorVistaHistoriaClinicaDlg(
                    GestorComponenteVista.getObjetoSeleccionado(pacienteABMPnl.getTabla()));
            g.abrirFormulario();
        }
    }//GEN-LAST:event_historiaClinicaBtnActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField apellidoTxt;
    private javax.swing.JButton buscarBtn;
    private javax.swing.JButton buscarLocalidadBtn;
    private util.components.RoundedTitlePanel busquedaPnl;
    private util.components.IntegerTextField codigoPostalTxt;
    private javax.swing.JButton generarListadoPacietesBtn;
    private javax.swing.JButton historiaClinicaBtn;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JComboBox localidadCmb;
    private javax.swing.JTextField nombreTxt;
    private util.components.IntegerTextField nroDocumentoTxt;
    private util.components.LongTextField nroHistoriaClinicaTxt;
    private util.components.TablaABMPnl pacienteABMPnl;
    private javax.swing.JComboBox provinciaCmb;
    // End of variables declaration//GEN-END:variables
}
